import { h } from 'vue';
import { NAvatar, NTag, NButton, NIcon } from 'naive-ui';
import { BasicColumn } from '@/components/Table';
import dayjs from 'dayjs';
// 文章结构类型定义
export interface ArticleItem {
  authorID: number;
  title: string;
  likeCount: number;
  favoriteCount: number;
  commentCount: number;
  creationTime: string | null;
  recommendationIndex: number;
  status: 'draft' | 'published' | 'pendingReview' | 'deleted';
  latitude: number;
  longitude: number;
  articleID: number;
}

// 文章状态映射
const articleStatusMap = {
  draft: '草稿',
  published: '已发布',
  pendingReview: '待审核',
  deleted: '已删除',
};

// 状态标签类型映射
const articleStatusTypeMap = {
  draft: 'default',
  published: 'success',
  pendingReview: 'warning',
  deleted: 'error',
};

// 表格列定义
export const columns: BasicColumn<ArticleItem>[] = [
  {
    title: '文章ID',
    key: 'articleID',
    width: 80,
  },
  {
    title: '作者ID',
    key: 'authorID',
    width: 80,
  },
  {
    title: '标题',
    key: 'title',
    width: 200,
  },
  {
    title: '点赞数',
    key: 'likeCount',
    width: 100,
  },
  {
    title: '收藏数',
    key: 'favoriteCount',
    width: 100,
  },
  {
    title: '评论数',
    key: 'commentCount',
    width: 100,
  },
  {
    title: '创建时间',
    key: 'createDate',
    width: 180,
    render(record) {
      // 使用 dayjs 进行日期格式化
      const formattedDate = dayjs(record.creationTime).format('YYYY-MM-DD HH:mm:ss');
      return h('span', {}, formattedDate);
    },
  },
  {
    title: '推荐指数',
    key: 'recommendationIndex',
    width: 120,
  },
  {
    title: '状态',
    key: 'status',
    width: 100,
    render(record) {
      return h(
        NTag,
        {
          type: articleStatusTypeMap[record.status] as any,
        },
        {
          default: () => articleStatusMap[record.status],
        }
      );
    },
  },
];

// 示例处理函数（你需要根据实际情况实现这些函数）
function handleEdit(article: ArticleItem) {
  console.log('Editing article:', article);
  // 实现编辑逻辑
}

function handleDelete(article: ArticleItem) {
  console.log('Deleting article:', article);
  // 实现删除逻辑
}
